import Dep from './Dep.js'
import observe from './observe'
export default function defineReactive(obj,key,value){
    const dep = new Dep()
    if(arguments.length == 2){
        value = obj[key]
    }
    let childOb = observe(value)
    Object.defineProperty(obj,key,{
        // 可枚举
        enumerable: true,
        // 可以被配置，比如可以被delete
        configurable: true,
        get(){
            console.log('你试图访问' + key + '属性');
            if(Dep.target){
                dep.depend(Dep.target)
                if(childOb){
                    childOb.dep.depend()
                }
            }
            return value
        },
        set(newValue){
            console.log('你试图改变' + key + '属性', newValue);
            if (value === newValue) {
                return;
            }
            value = newValue;
            childOb = observe(newValue)
            dep.notify()
        }
    })
}